const install = (Vue, vm) => {
    Vue.prototype.toPage=(url)=>{
      uni.navigateTo({url})
    }
    Vue.prototype.$tools = {}
    //显示toast
    Vue.prototype.$tools.showToast = (toast) => {
        uni.showToast({title: toast, icon: 'none'})
    }
    //路由调整
    Vue.prototype.$tools.pageGo = (url) => {
        uni.navigateTo({url})
    }
    //路由延迟跳转-0.7s之后。
    Vue.prototype.$tools.pageGoDelay = (url, toast, delay = 500) => {
        if (toast) uni.showToast({title: toast, icon: 'none'})
        setTimeout(() => uni.navigateTo({url}), delay)
    }
    //路由延迟跳转-0.7s之后。
    Vue.prototype.$tools.pageGoRedirectDelay = (url, toast, delay = 500) => {
        if (toast) uni.showToast({title: toast, icon: 'none'})
        setTimeout(() => uni.redirectTo({url}), delay)
    }
    //延迟返回-如果有提示则提示toast
    Vue.prototype.$tools.pageBackDelay = (toast) => {
        if (toast) uni.showToast({title: toast, icon: 'none'})
        setTimeout(() => uni.navigateBack(), 700)
    }
    //页面数据回调：回调页面的路径、回调页面的data对应的key、回调key对应的value
    Vue.prototype.$tools.pageDataBack = (pageRoute, dataKey, value) => {
        let pages = getCurrentPages(), targetPage = pages.find(page => page.route === pageRoute)
        if (targetPage) targetPage.$vm[dataKey] = value;//重点$vm
    }
    //页面数据回调：回调页面的路径、回调页面的data对应的Obj的key，回调Obj多个值
    Vue.prototype.$tools.pageDataObjBack = (pageRoute, ObjKey, valueObj) => {
        let pages = getCurrentPages(), targetPage = pages.find(page => page.route === pageRoute)
        if (targetPage) targetPage.$vm[ObjKey] = {...targetPage.$vm[ObjKey], ...valueObj};
    }
    //页面方法回调：回调页面的路径、回调页面的方法、回调页面的参数
    Vue.prototype.$tools.pageCallBack = (pageRoute, call, params) => {
        let pages = getCurrentPages(), targetPage = pages.find(page => page.route === pageRoute)
        if (targetPage) targetPage.$vm[call](params);//重点$vm
    }
    //页面数据回调延迟-0.5s之后。参数同上
    Vue.prototype.$tools.pageCallBackDelay = (pageRoute, call, params) => {
        setTimeout(() => vm.$tools.pageCallBack(pageRoute, call, params), 500)
    }
    //显示文本弹窗并复制
    Vue.prototype.$tools.showCopyModal = (content) => {
        uni.showModal({content, success: (res) => uni.setClipboardData({data: content})})
    }
}
export default {
    install
}
